selection | NN n/a IE 4 DOM n/a | ||
The selection object represents zero or more characters that have been either explicitly selected in a document by the user or selected under script control. All actions on the content of a selection are done via a TextRange object, which can be created from the selection object (see the TextRange object). TextRange and selection objects are available in Navigator 4 only in the Win32 environment. The selection object belongs to the document object. Navigator 4 offers script access to the text selected in a document via the document.getSelection( ) method. In all browsers, be aware that clicking on buttons deselects the
current text selection. Therefore, all scripted action involving
selections must be triggered by select events or functions invoked by
a timer (see the window.setTimeout( ) method
description in | |||
Object Model Reference
|
type | NN n/a IE 4 DOM n/a | ||
Read-only | |||
Whether the current selection object has one or more characters selected or is merely an insertion point. | |||
Exampleif (document.selection.type == "Text") { ... } | |||
Value Either of two constant values (as a string): None | Text. | |||
|
clear( ) | NN n/a IE 4 DOM n/a |
Deletes the content of the current selection in a document. For example, the event handler in the following tag deletes any selected text of the P element two seconds after the user starts making the selection: <P onSelectStart="setTimeout('document.selection.clear( )',2000)"> | |
Returned Value None. | |
Parameters None. |
createRange( ) | NN n/a IE 4 DOM n/a |
Creates a TextRange object from the current selection object. After a statement like the following: var myRange = document.selection.createRange( ) scripts can then act on the content of the selected text. | |
Returned Value TextRange object. | |
Parameters None. |
empty( ) | NN n/a IE 4 DOM n/a |
Deselects the current selection and sets the selection object's type property to None. There is no change to the content that had been selected. | |
Returned Value None. | |
Parameters None. |